package com.goldman.aplt.util;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @description：
 * @author： chenxiangxiang
 * @create： 2024/1/24 20:59
 */
public class NetUtil {

    private static final String UNKNOWN = "unknown";

    public static String getClientIP(HttpServletRequest request) {
        String clientIp = request.getHeader("x-forwarded-for");
        if (StringUtils.isBlank(clientIp) || UNKNOWN.equalsIgnoreCase(clientIp)) {
            clientIp = request.getHeader("Proxy-Client-IP");
        }
        if (StringUtils.isBlank(clientIp) || UNKNOWN.equalsIgnoreCase(clientIp)) {
            clientIp = request.getHeader("WL-Proxy-Client-IP");
        }
        if (StringUtils.isBlank(clientIp) || UNKNOWN.equalsIgnoreCase(clientIp)) {
            clientIp = request.getRemoteAddr();
        }
        return clientIp;
    }
}